<template>
  <view class="good-list">
    <uni-list>
      <uni-list-item v-for="(item, index) in list" :key="index">
        <template slot="body">
          <view class="u-cell-group">
            <view class="title">
              {{$t('指纹所属人姓名')}}：
              <u-tag :text="item.userName" shape="circleRight" type="success" />
            </view>
            <view>{{$t('用户注册日期')}}：{{ item.createDate }}</view>
            <view>{{$t('所属组织')}}：{{ item.departmentNames }}</view>
            <view>{{$t('手机号码')}}：{{ item.phone }}</view>
            <view v-if="item.fingerCreateDate">{{$t('指纹录入日期')}}：{{ item.fingerCreateDate }}</view>
            <view>
              <u-button
                v-if="item.finger"
                size="mini"
                type="error"
                @click="delPersonsOK(item.userId)"
              >
                {{$t('指纹删除')}}
              </u-button>
              <u-button v-else size="mini" type="success" @click="InputPersonsOK(item.userId)">
                {{$t('指纹录入')}}
              </u-button>
            </view>
          </view>
        </template>
      </uni-list-item>
    </uni-list>
  </view>
</template>

<script>
import { mapGetters, mapMutations } from 'vuex'

export default {
  computed: {
    ...mapGetters(['userInfo', 'api']),
  },
  props: {
    list: {
      type: [Array],
      default() {
        return []
      }
    },
    signetId: {
      type: String,
      default() {
        return ''
      }
    }
  },
  data() {
    return {}
  },
  mounted() {
  },
  methods: {
    //指纹录入确认
    InputPersonsOK(userId) {
      let req = {
        userId: userId,
        signetId: this.signetId
      }
      //指纹录入
      this.$u.post(this.api.GLOBAL_device_finger_fingerPrint, req).then((res) => {
        if (res.code === 200) {
          uni.showToast({
            icon: 'none',
            title: this.$t(res.msg),
            duration: 2000
          })
        }
      })
    },
    //指纹删除
    delPersonsOK(userId) {
      uni.showModal({
        title: this.$t('提示'),
        content: this.$t('是否删除当前选择的指纹') + '？',
        success: (res) => {
          if (res.confirm) {
            let req = {
              userId: userId,
              signetId: this.signetId
            }
            //指纹删除
            this.$u.post(this.api.GLOBAL_device_finger_cleanOne, req).then((res) => {
              if (res.code === 200) {
                uni.showToast({
                  icon: 'none',
                  title: this.$t(res.msg),
                  duration: 2000
                })
              }
            })
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.good-list {
  background-color: #fff;
  width: 100%;

  .u-cell-group {
    font-size: 28rpx;
    color: #888;
    line-height: 48rpx;
    box-sizing: border-box;
    width: 100%;
    display: flex;
    flex-direction: column;

    .title {
      font-weight: bold;
      color: #000;
    }
  }
}
</style>
